<template>
  <view class="wrapPay">
    <view
      class="btn"
      style="
        position: fixed;
        bottom: 100rpx;
        right: 50rpx;
        color: #fff;
        z-index: 33;
        padding: 8rpx 24rpx;
        background: #5c8eff;
      "
      @tap="payFun"
      >支付</view
    >
  </view>
</template>

<script setup lang="ts">
// 支付组件
import { reactive, watch } from 'vue'
import { paying } from '@/api/hmm'
const state = reactive({
  userInfoNew: {}
})
const payFun = () => {
  console.log(123)
  state.userInfoNew = uni.getStorageSync('userInfo')
    ? JSON.parse(uni.getStorageSync('userInfo'))
    : {}
  console.log(state.userInfoNew)
  let param = {
    title: '测试',
    amount: '0.01',
    openId: state.userInfoNew.openId,
    channel: 'wechat_pay',
    userId: 123,
    method: 'jsapi'
  }
  uni.showLoading({
    title: ''
  })
  paying(param).then((res) => {
    uni.hideLoading()
    let payParam = JSON.parse(res.data.payBody)
    uni.requestPayment({
      provider: 'wxpay',
      timeStamp: payParam.timeStamp,
      nonceStr: payParam.nonceStr,
      package: payParam.package,
      signType: payParam.signType,
      paySign: payParam.paySign,
      success: function (res) {
        console.log('success:' + JSON.stringify(res))
      },
      fail: function (err) {
        // uni.showToast({
        //   title: '支付失败,请重试',
        //   icon: 'error',
        //   duration: 2000
        // })
        console.log('fail:' + JSON.stringify(err))
      }
    })
  })
}
</script>

<style lang="scss" scoped></style>
